package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import service.MessageServiceI;
import pojo.User;

@Controller
@RequestMapping("message")
public class MessageController {

	@Autowired
	private MessageServiceI messageServiceI;
	
	/**
	 * 
	 * @Title: deleteOne   
	 * @Description: TODO(删除单个文章)   
	 * @param: @param request
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequestMapping("deleteOne")
	@ResponseBody
	public String  deleteOne(HttpServletRequest request) {
		Integer messageId=Integer.valueOf(request.getParameter("messageId")).intValue();
		boolean bool=messageServiceI.removeMessageByMessageId(messageId);
		if(bool) {
			return "success";
		}else {
			return "false";
		}
	}
	
	@RequestMapping("deleteAll")
	@ResponseBody
	@Transactional(rollbackFor=Exception.class)
/**
　　* @param [session]
　　* @return java.lang.String
　　* @author：千夜
　　* @date 2019/4/20 22:15
 　 * @description: 删除所有消息
　　*/
	public String deleteAll(HttpSession session) {
		User user=(User) session.getAttribute("user");
		if(user==null) {
			return "unlogin";
		}else {
			Integer userId=user.getUserId();
			String flag="all";
			try {
				messageServiceI.RemoveMessageByUserId(userId, flag);
			} catch (Exception e) {
				e.printStackTrace();
				return "false";
			}
			return "success";
		}

	}
}
